import {createWebHistory,createRouter,RouteRecordRaw} from 'vue-router'

import {beforeEach,afterEach} from './guard'

const routes:Array<RouteRecordRaw> = [
    {
        path:'/',
        component:()=>import("@/pages/home.vue"),
        redirect:'/dashboard',
        children:[
            {
                path:'dashboard',
                name: 'dashboard',
                redirect:'/dashboard/console',
                children:[
                    {
                        path:'console',
                        name:'console',

                        meta:{title:'主控制台',isKeepAlive:true,isClose:false,menuName:'1-1'},
                        component:()=>import('@/pages/dashboard/console.vue')
                    }
                ]
            },
            {
                path:'content',
                name: 'content',
                redirect:'/content/articles',
                children:[
                    {
                        path:'articles',
                        name:'articles',
                        meta:{title:'文章管理',isKeepAlive:true,isClose:true,menuName:'2-1'},
                        component:()=>import('@/pages/content/articles.vue')
                    },
                    {
                        path:'comment',
                        name:'comment',
                        meta:{title:'评论管理',isKeepAlive:true,isClose:true,menuName:'2-2'},
                        component:()=>import('@/pages/content/comment.vue')
                    },
                    {
                        path:'report',
                        name:'report',
                        meta:{title:'举报管理',isKeepAlive:true,isClose:true,menuName:'2-3'},
                        component:()=>import('@/pages/content/report.vue')
                    }
                ]
            },
            {
                path:'user-admin',
                name: 'user-admin',
                redirect:'/user-admin/new-user',
                children:[
                    {
                        path:'new-user',
                        name:'new-user',
                        meta:{title:'添加用户',isKeepAlive:true,isClose:true,menuName:'3-1'},
                        component:()=>import('@/pages/user-admin/newUser.vue')
                    },
                    {
                        path:'active-user',
                        name:'active-user',
                        meta:{title:'活跃用户',isKeepAlive:true,isClose:true,menuName:'3-2'},
                        component:()=>import('@/pages/user-admin/activeUser.vue')
                    }
                ]
            },
            {
                name:'socket',
                path:'/socket',
                redirect:'/socket/chat',
                children:[
                    {
                        meta:{title:'聊天室',isKeepAlive:true,isClose:true,menuName:'5-1'},
                        name:'chat',
                        path:'chat',
                        component:()=>import('@/pages/socket/chat.vue')
                    }
                ]
            }
        ]
    },
    {
        path: '/login',
        name:'login',
        meta:{title:'登录'},
        component:()=>import('@/pages/verify/login.vue')
    },
    {
        path: '/register',
        name:'register',
        meta:{title:'注册'},
        component:()=>import('@/pages/verify/register.vue')
    },
    {
        path: '/blank',
        name:'blank',
        component:()=>import('@/pages/blank')
    },
    {
        path: '/:catchAll(.*)',
        name:'not found',
        component:()=>import('@/pages/exception/404')
    },

]

const router = createRouter({
    routes,
    history:createWebHistory()
})

router.beforeEach(beforeEach)

router.afterEach(afterEach)

export default router